package kingiis.utils.simpleapp;

import android.app.Activity;
import android.os.Message;

import java.lang.ref.WeakReference;

/**
 * Created by King on 2017/12/29 0029.
 */

public abstract class Handler extends android.os.Handler {
    WeakReference<Activity> weakReference;

    public Handler(Activity context) {
        weakReference = new WeakReference<Activity>(context);
    }

    @Override
    public void handleMessage(Message msg) {
        super.handleMessage(msg);
        if (weakReference.get() != null) {
            delMsg(msg);
            return;
        }
    }

    public abstract void delMsg(Message msg);

    public synchronized Message M(int what, String str) {
        Message m = new Message();
        m.what = what;
        m.obj = str;
        return m;
    }
}
